import request from '@/utils/request'
import qs from 'qs'

/**
 * get数据请求
 * @param url
 * @param paramData
 */
export function getData(url, paramData) {
  var getParam = ''
  for (var i in paramData) {
    if (getParam !== '') {
      getParam += '&'
    }
    getParam += i + '=' + encodeURIComponent(paramData[i])
  }
  if (getParam !== '') {
    getParam = '?' + getParam
  }

  return request({
    url: url + getParam,
    method: 'get'
  })
}

/**
 * post数据请求
 * @param url
 * @param paramData
 */
export function postData(url, paramData) {
  var postParam = qs.stringify(paramData)
  return request({
    url: url,
    method: 'post',
    data: postParam
  })
}

/**
 * post数据请求 JSON格式数据
 * @param url
 * @param paramData
 */
export function postDataJson(url, paramData) {
  return request({
    url: url,
    method: 'post',
    data: JSON.stringify(paramData),
    headers: {
      "Content-Type": "application/json",
    }
  })
}


/**
 * post数据请求 formData格式数据
 * @param url
 * @param paramData
 */
export function postFormData(url, paramData) {
  return request({
    url: url,
    method: 'post',
    data: paramData,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryTGmYk4BsaUXlN2Wp'
    }
  })
}
